package com.niodata.dp.task.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.niodata.dp.util.TimeUtil;
import java.util.Date;

/**
 * READY(10), PREPARING(20), RUNNING(30), PAUSED(40), SUCCEEDED(50), KILLED(60), FAILED(70),
 * FAILED_FINISHING(80), SKIPPED(90), DISABLED(100), QUEUED(110), FAILED_SUCCEEDED(120),
 * CANCELLED(130); Task execute instance.
 */
public class TaskExecution {

  private String taskId;
  private Date startTime;
  private Date endTime;
  private int execId;
  private String status;
  private boolean success;
  private String taskName;
  private String flowName;
  private int executorId = -1;

  @JsonIgnore
  private TaskExecutionDetail taskExecutionDetail;

  public TaskExecutionDetail getTaskExecutionDetail() {
    return taskExecutionDetail;
  }

  public void setTaskExecutionDetail(TaskExecutionDetail taskExecutionDetail) {
    this.taskExecutionDetail = taskExecutionDetail;
  }

  public String getTaskId() {
    return taskId;
  }

  public void setTaskId(String taskId) {
    this.taskId = taskId;
  }

  public Date getStartTime() {
    return startTime;
  }

  public void setStartTime(Date startTime) {
    this.startTime = startTime;
  }

  public Date getEndTime() {
    return endTime;
  }

  public void setEndTime(Date endTime) {
    this.endTime = endTime;
  }

  public int getExecId() {
    return execId;
  }

  public void setExecId(int execId) {
    this.execId = execId;
  }

  public boolean isSuccess() {
    return success;
  }

  public void setSuccess(boolean success) {
    this.success = success;
  }

  public String getStatus() {
    return status;
  }

  public void setStatus(String status) {
    this.status = status;
  }

  public String getTaskName() {
    return taskName;
  }

  public void setTaskName(String taskName) {
    this.taskName = taskName;
  }

  public String getFlowName() {
    return flowName;
  }

  public void setFlowName(String flowName) {
    this.flowName = flowName;
  }

  public int getExecutorId() {
    return executorId;
  }

  public void setExecutorId(int executorId) {
    this.executorId = executorId;
  }

  public String getDuration() {
    if (startTime != null && endTime != null && endTime.compareTo(startTime) > 0) {
      return TimeUtil.toReadableDuration(startTime, endTime);
    }
    return "";
  }
}
